package de.bht.fb6.cg1.exercise1;

import java.awt.Color;

/**
 * Event throwen by a {@link ColorPanel} on color change from it.
 * 
 * @author Dominik Eckelmann
 */
public class ColorSyncEvent {

    /**
     * new color from the {@link ColorPanel}
     */
    private final Color color;

    /**
     * {@link ColorPanel} that has throwen the event.
     */
    private final ColorPanel source;

    /**
     * creates a new event.
     * 
     * @param c         new color from the {@link ColorPanel}
     * @param source    the {@link ColorPanel} itself
     */
    public ColorSyncEvent(final Color c, final ColorPanel source) {
        color = c;
        this.source = source;
    }

    /**
     * returns the new color
     * 
     * @return new color in the {@link ColorPanel}
     */
    public Color getColor() {
        return color;
    }

    /**
     * get the throwen {@link ColorPanel}
     * 
     * @return the event source
     */
    public ColorPanel getSource() {
        return source;
    }
    
    /**
     * returns some event informations
     */
    @Override
    public String toString() {
        return "ColorSyncEvent: new Color = " + color;
    }

    /* Create a hashcode from a ColorSyncEvent
     * 
     * @return numerical hashcode
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((color == null) ? 0 : color.hashCode());
        result = prime * result + ((source == null) ? 0 : source.hashCode());
        return result;
    }

    /* compares a ColorSyncEvent to an object.
     * 
     * @param obj Object to compare with
     * @return evaluate to true when obj is equals to this
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof ColorSyncEvent)) {
            return false;
        }
        ColorSyncEvent other = (ColorSyncEvent) obj;
        if (color == null) {
            if (other.color != null) {
                return false;
            }
        } else if (!color.equals(other.color)) {
            return false;
        }
        if (source == null) {
            if (other.source != null) {
                return false;
            }
        } else if (!source.equals(other.source)) {
            return false;
        }
        return true;
    }
    
    
}
